package com.juc.concurrency.jucExample.executorsThreadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * newCachedThreadPool
 * newScheduledThreadPool
 * 可创建的最大线程数是Integer.MAX_VALUE 会导致OOM
 */
@Slf4j
public class NewCachedThreadPoolExample1 {

    public static void main(String[] args) {
        //点进方法看，corePoolSize=Integer.MAX_VALUE
        ExecutorService executorService = Executors.newCachedThreadPool();

        for (int i = 0; i < 100; i++) {
            final int index = i;
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    log.info("task:{}", index);
                }
            });
        }
        executorService.shutdown();
    }
}
